package jsyf.oa.service.wechartSec;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.wechartSec.WechartDeviceBrandEntity;
import jsyf.oa.facade.wechartSec.WechartDeviceBrandFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jsyf.oa.dao.wechartSec.WechartDeviceBrandDao;

import java.util.List;

/**
 * Created by Administrator on 2018/4/8.
 */
@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class WechartDeviceBrandService implements WechartDeviceBrandFacade {

    @Autowired
    private WechartDeviceBrandDao deviceBrand2Dao;

    @Override
    public String save(String jsonData) {
        WechartDeviceBrandEntity entity = JSON.toJavaObject(JSON.parseObject(jsonData), WechartDeviceBrandEntity.class);
        Integer rows;
        if ("0".equals(entity.getId()) || StringUtils.isBlank(entity.getId())) {
            rows = deviceBrand2Dao.add(entity);
        } else {
            WechartDeviceBrandEntity deviceBrandEntity = (WechartDeviceBrandEntity) deviceBrand2Dao.getIBaseEntityById(entity.getId());
            deviceBrandEntity.setName(entity.getName());
            deviceBrandEntity.setSortNo(entity.getSortNo());
            deviceBrandEntity.setDelFlag(entity.getDelFlag());
            rows = deviceBrand2Dao.update(deviceBrandEntity);
        }
        return rows == 0 ? "" : entity.getId();
    }
    @Override
    public List<JSONObject> getBrandList() {
        List<JSONObject> jsonObjectList = this.deviceBrand2Dao.getJSONListByCondition(" ", null);
        return jsonObjectList;
    }

//    @Override
//    public Boolean delById(String id) {
//        return deviceBrandDao.delById(id) > 0;
//    }
//
//    @Override
//    public JSONObject bindOA(String jsonData) {
//        JSONObject object = JSON.parseObject(jsonData);
//        String tel = object.getString("tel");
//        String pwd = object.getString("pwd");
//        String wxId = object.getString("wxId");
//        String wxAvatar = object.getString("wxAvatar");
//        List<JSONObject> listUser = deviceBrandDao.getJSONListByCondition(" and TEL =? and PWD=? AND DEL_FLAG =0", new Object[]{tel, pwd});
//        if (listUser != null && listUser.size() > 0) {
//            JSONObject userObj = listUser.get(0);
//            //更新微信信息
//            WechartDeviceBrandEntity user = JSON.toJavaObject(userObj, WechartDeviceBrandEntity.class);
//            if (!wxId.isEmpty() && !wxAvatar.isEmpty()) {
//                user.setWxId(wxId);
//                user.setWxAvatar(wxAvatar);
//                deviceBrandDao.update(user);
//            }
//            return JSON.parseObject(JSON.toJSONString(user));
//        }
//        return null;
//    }
}